<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>Interviews 0001 | 越努力，越幸运</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="算法题 0001 算法结果如下12345678910111213141516171819&#x2F;&#x2F; 实现函数fn&#x2F;*console.log(&quot;fn: &quot;, fn(    function (x) &amp;#123;        return x + 3    &amp;#125;,    function (x) &amp;#123;        return x &#x2F; 2    &amp;#125;,    function (">
<meta property="og:type" content="article">
<meta property="og:title" content="Interviews 0001">
<meta property="og:url" content="https://zhanqj.gitee.io/2020/01/05/Interview0001/index.html">
<meta property="og:site_name" content="越努力，越幸运">
<meta property="og:description" content="算法题 0001 算法结果如下12345678910111213141516171819&#x2F;&#x2F; 实现函数fn&#x2F;*console.log(&quot;fn: &quot;, fn(    function (x) &amp;#123;        return x + 3    &amp;#125;,    function (x) &amp;#123;        return x &#x2F; 2    &amp;#125;,    function (">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-01-05T09:08:52.120Z">
<meta property="article:modified_time" content="2020-01-05T09:36:09.405Z">
<meta property="article:author" content="Lenglu">
<meta property="article:tag" content="Web">
<meta property="article:tag" content="前端">
<meta property="article:tag" content="JavaScript">
<meta property="article:tag" content="CSS">
<meta property="article:tag" content="HTML">
<meta property="article:tag" content="Vue">
<meta property="article:tag" content="小程序">
<meta property="article:tag" content="H5">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/blog/atom.xml" title="越努力，越幸运" type="application/atom+xml">
  
  
    <link rel="icon" href="/blog/favicon.ico">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

<meta name="generator" content="Hexo 4.2.0"></head>

<body>
  
    <div id="live2d-widget">
      <canvas id="live2dcanvas" width="200" height="400" style="position: fixed; opacity: 0.7; right: 0px; bottom: -20px; z-index: 99999; pointer-events: none;"></canvas>
    </div>
  
  
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog/" id="logo">越努力，越幸运</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/blog/">首页</a>
        
          <a class="main-nav-link" href="/blog/archives">归档</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/blog/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://zhanqj.gitee.io"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-Interview0001" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/blog/2020/01/05/Interview0001/" class="article-date">
  <time datetime="2020-01-05T09:08:52.120Z" itemprop="datePublished">2020-01-05</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Interviews 0001
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>算法题 0001</p>
<h2 id="算法"><a href="#算法" class="headerlink" title="算法"></a>算法</h2><h3 id="结果如下"><a href="#结果如下" class="headerlink" title="结果如下"></a>结果如下</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">// 实现函数fn</span><br><span class="line">/*</span><br><span class="line">console.log(<span class="string">"fn: "</span>, fn(</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x + 3</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x / 2</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x * 3</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x - 2</span><br><span class="line">    &#125;,</span><br><span class="line">    ...</span><br><span class="line">))*/</span><br><span class="line">// fn函数返回一个方法b</span><br><span class="line">调用b(10), 返回结果： ( ( ( ( 10  - 2 ) * 3 ) / 2 ) + 3 )</span><br></pre></td></tr></table></figure>

<h3 id="算法实现"><a href="#算法实现" class="headerlink" title="算法实现"></a>算法实现</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="function"><span class="title">fn</span></span>() &#123;</span><br><span class="line">    var args = arguments;</span><br><span class="line">    var len = args.length;</span><br><span class="line">    <span class="built_in">return</span> <span class="keyword">function</span>(num) &#123;</span><br><span class="line">        var str = <span class="string">"( "</span> + num + <span class="string">" "</span>;</span><br><span class="line">        <span class="keyword">for</span>(var i = len; i &gt; -1; i--) &#123;</span><br><span class="line">            <span class="keyword">if</span> (Object.prototype.toString.call(args[i]) === <span class="string">"[object Function]"</span>) &#123;</span><br><span class="line">//                 console.log(args[i])</span><br><span class="line">                var regExp =/<span class="keyword">function</span>\s*\w*\(([\s\S]*?)\)/;</span><br><span class="line">                <span class="keyword">if</span>(regExp.test(args[i].toString()))&#123;</span><br><span class="line">                    console.log(RegExp.<span class="variable">$0</span>)</span><br><span class="line">                    var a = RegExp.<span class="variable">$1</span></span><br><span class="line">                    console.log(a);</span><br><span class="line">                    console.log(RegExp.<span class="variable">$2</span>)</span><br><span class="line">                &#125;</span><br><span class="line">                var s = args[i].toString().split(<span class="string">"\n"</span>).slice(1, 2)[0].split(a)[1]</span><br><span class="line">                <span class="keyword">if</span> (i === 0) &#123;</span><br><span class="line">                    str += s + <span class="string">" )"</span></span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    str = <span class="string">"( "</span> + str + s + <span class="string">" )"</span></span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">return</span> str</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">var b = fn(</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x + 3</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x / 2</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x * 3</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x - 2</span><br><span class="line">    &#125;</span><br><span class="line">)</span><br><span class="line">console.log(b(10))</span><br><span class="line">/*</span><br><span class="line">console.log(<span class="string">"fn: "</span>, fn(</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x + 3</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x / 2</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x * 3</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="keyword">function</span> (x) &#123;</span><br><span class="line">        <span class="built_in">return</span> x - 2</span><br><span class="line">    &#125;</span><br><span class="line">))*/</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="https://zhanqj.gitee.io/2020/01/05/Interview0001/" data-id="ck50u30cd0000xgtt08dwguyq" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/blog/2020/01/05/Interview0002/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Interviews 0002
        
      </div>
    </a>
  
  
    <a href="/blog/2020/01/05/hello-world/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Hello World</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/01/">一月 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog/2020/01/05/Interview0002/">Interviews 0002</a>
          </li>
        
          <li>
            <a href="/blog/2020/01/05/Interview0001/">Interviews 0001</a>
          </li>
        
          <li>
            <a href="/blog/2020/01/05/hello-world/">Hello World</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 Lenglu<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/blog/" class="mobile-nav-link">首页</a>
  
    <a href="/blog/archives" class="mobile-nav-link">归档</a>
  
</nav>
    

<!-- <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> -->
<script src="https://cdn.bootcss.com/jquery/2.0.3/jquery.min.js"></script>
<script src="/blog/js/clickLove.js"></script>

  <script src="/blog/js/girl/L2Dwidget.min.js"></script>
  <script>
    L2Dwidget.init();
  </script>




  
<link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.css">

  
<script src="/blog/fancybox/jquery.fancybox.pack.js"></script>




<script src="/blog/js/script.js"></script>




  </div>
</body>
</html>